// 配件相关的接口
import service from "./index";

const prefix = "/accessory";

/**
 * 新增配件信息
 */
export function addAccessory(accessory) {
  return service({
    url: `${prefix}/addAccessory`,
    method: "POST",
    data: accessory,
  });
}

export function deleteById(id) {
  return service({
    url: `${prefix}/deleteById/${id}`,
    method: "DELETE",
  });
}

/**
 * 根据id修改配件信息
 */
export function updateById(accessory) {
  return service({
    url: `${prefix}/updateById`,
    method: "PUT",
    data: accessory,
  });
}

/**
 * 根据商品id查询配件信息
 */
export function listPageByGoodsId(goodsId) {
  return service({
    url: `${prefix}/listPageByGoodsId/${goodsId}`,
    method: "GET",
  });
}

/**
 * 分页查询
 */
export function pageList(pageInfo, accessory) {
  const params = {};
  if (pageInfo) {
    params.pageNum = pageInfo.pageNum;
    params.pageSize = pageInfo.pageSize;
  }
  if (accessory) {
    params.name = accessory.name;
    params.assortId = accessory.assortId;
    params.systemArg = accessory.systemArg;
  }
  return service({
    url: `${prefix}/pageList`,
    method: "GET",
    params: params,
  });
}

// 根据id查询配件信息
export function getById(id) {
  return service({
    url: `${prefix}/getById/${id}`,
    method: "GET",
  });
}

// 根据部件名称查询部件信息
export function searchByName(name) {
  return service({
    url: `${prefix}/searchByName`,
    method: "GET",
    params: {
      name: name,
    },
  });
}
